package com.baturu.vin.ford.dal.dao;

import com.baturu.vin.ford.dal.entity.FordVinInfoEntity;
import com.baturu.vin.ford.dto.CarTypeDetail;
import com.baturu.vin.ford.dto.FordLessInfoLevelDTO;
import com.baturu.vin.ford.dto.FordV2VinAnalyserResultDTO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface FordVinInfoDAO {

    @Insert({"<script>" +
            "INSERT INTO ford_vin_info",
            "(catalogCode,catalogType,vin,bodyNumber,vehicleDataSource,buildDate,transmission,`engine`,modelCode,exteriorPaint,",
            "modelBeginDate,sidoNumber,cabStyle,modelEndDate,models,modelID,engineNumber,`match`,modelYear,rego,interpretationAVSData,",
            "displayBuildDate,genericVehicleInformation,applicableRegions,vehicleMarket,marketCode,marketName) VALUES ",
            "(#{item.catalogCode}, #{item.catalogType}, #{item.vin}, #{item.bodyNumber}, #{item.vehicleDataSource}, ",
            "#{item.buildDate}, #{item.transmission}, #{item.engine}, #{item.modelCode}, #{item.exteriorPaint}, ",
            "#{item.modelBeginDate}, #{item.sidoNumber}, #{item.cabStyle}, #{item.modelEndDate}, #{item.models}, ",
            "#{item.modelID}, #{item.engineNumber}, #{item.match}, #{item.modelYear}, #{item.rego}, #{item.interpretationAVSData},",
            " #{item.displayBuildDate}, #{item.genericVehicleInformation}, #{item.applicableRegions}, #{item.vehicleMarket},",
            " #{item.marketCode}, #{item.marketName}) ",
            "ON DUPLICATE KEY UPDATE ",
            "catalogCode = #{item.catalogCode},",
            "catalogType = #{item.catalogType},",
            "bodyNumber = #{item.bodyNumber},",
            "vehicleDataSource = #{item.vehicleDataSource},",
            "buildDate = #{item.buildDate},",
            "transmission = #{item.transmission},",
            "`engine` = #{item.engine},",
            "modelCode = #{item.modelCode},",
            "exteriorPaint = #{item.exteriorPaint},",
            "modelBeginDate = #{item.modelBeginDate},",
            "sidoNumber = #{item.sidoNumber},",
            "cabStyle = #{item.cabStyle},",
            "modelEndDate = #{item.modelEndDate},",
            "models = #{item.models},",
            "modelID = #{item.modelID},",
            "engineNumber = #{item.engineNumber},",
            "`match` = #{item.match},",
            "modelYear = #{item.modelYear},",
            "rego = #{item.rego},",
            "interpretationAVSData = #{item.interpretationAVSData},",
            "displayBuildDate = #{item.displayBuildDate},",
            "genericVehicleInformation = #{item.genericVehicleInformation},",
            "applicableRegions = #{item.applicableRegions},",
            "vehicleMarket = #{item.vehicleMarket},",
            "marketCode = #{item.marketCode},",
            "marketName = #{item.marketName}",
            "</script>"})
    void saveVin(@Param("item") Map<String, Object> vinItem);

    @Select({"select vin as vinCode, catalogCode, catalogType, modelYear, `engine`, transmission,exteriorPaint,cabStyle,interpretationAVSData, buildDate, displayBuildDate ",
            "from ford_vin_info ",
            "where vin = #{vinCode}"})
    FordVinInfoEntity queryByVinCode(@Param("vinCode") String vinCode);

    @Select({"SELECT vinCode,lessInfo, date, carType, carBody, ver, engine, transmission, driven, displacement, airc, area, carOilColor, enviroment, trim,carradio ",
            "FROM ford_epc_vin",
            "WHERE vinCode = #{vinCode}",})
    List<FordV2VinAnalyserResultDTO> queryV2ByVinCode(@Param("vinCode") String vinCode);

    @Select({"<script>SELECT idx,carTypeDetailIdx,name FROM ford_epc_car_type ",
            "WHERE country = #{country}",
            "AND carType = #{carType}",
            "AND begin &lt;= #{date}",
            "AND end &gt;= #{date} LIMIT 1</script>",})
    CarTypeDetail queryV2CarTypeId(@Param("country") String country, @Param("date") String date, @Param("carType") String carType);

    @Select({"SELECT en FROM ford_self_vin_en WHERE vin = #{vin} limit 1"})
    String queryCountryByPreThree(@Param("vin") String vin);

    @Select({"SELECT vinIdx,grade, lessInfoIndex, lessInfo FROM ford_epc_less_info_deal ",
            "WHERE vinIdx >= #{start} AND vinIdx <= #{end}"})
    List<FordLessInfoLevelDTO> queryLessInfoIdx(@Param("start") Integer start, @Param("end") Integer end);

    @Select({"SELECT name,carSystem FROM ford_epc_ignore_carsystem"})
    List<Map<String,String>> queryIgnoreCarSystem();

    @Select({"SELECT engine FROM `ford_epc_car_type_detail` WHERE carType  = #{carType} limit 1"})
    String queryCarTypeEngine(@Param("carType") String carType);

}